/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import bc.TallaPrendaFacadeLocal;
import be.TallaPrenda;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

/**
 *
 **Copyright  2011 Yury Daniel Zavaleta De la Cruz
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and  limitations under the License.
 */
@ManagedBean
@SessionScoped
public class ManagedBeanTallaPrenda implements Serializable {
    @EJB
    private TallaPrendaFacadeLocal tallaPrendaFacade;
private List<TallaPrenda> lista;

  private List<SelectItem> tallaprendasItems = new LinkedList<SelectItem>();
private HashMap<Integer, TallaPrenda> mytallaprendas = new HashMap<Integer,TallaPrenda>();
private TallaPrenda talla;

    public ManagedBeanTallaPrenda() {
        talla = new TallaPrenda();
    }

    public List<TallaPrenda> getLista_tallas(){
        try {
            lista = tallaPrendaFacade.findAll();
        } catch (Exception e) {
        e.printStackTrace();
        }
    return lista;
    }

    public TallaPrenda getTalla() {
        return talla;
    }

    public void setTalla(TallaPrenda talla) {
        this.talla = talla;
    }

    public HashMap<Integer, TallaPrenda> getMytallaprendas() {
        return mytallaprendas;
    }

    public void setMytallaprendas(HashMap<Integer, TallaPrenda> mytallaprendas) {
        this.mytallaprendas = mytallaprendas;
    }

    public List<SelectItem> getTallaprendasItems() {
         lista = new ArrayList<TallaPrenda>();
        tallaprendasItems = new LinkedList<SelectItem>();
        lista = tallaPrendaFacade.findAll();
        for(TallaPrenda p: lista){
        mytallaprendas.put(p.getIdTallaPrenda(), p);
            tallaprendasItems.add(new SelectItem(p, p.getNombreTallaPrenda()));
        }
        return tallaprendasItems;
    }

    public void setTallaprendasItems(List<SelectItem> tallaprendasItems) {
        this.tallaprendasItems = tallaprendasItems;
    }

     public TallaPrenda getTallaprenda(Integer id) {
           return (TallaPrenda) mytallaprendas.get(id);

    }

     public String nueva(){
     talla = new TallaPrenda();
     return "nueva_talla";
     }

     public String nueva_ubicacion3(){
     talla = new TallaPrenda();
     return "nueva_ubicacion3";
     }

     public String crear(){

         try {
             tallaPrendaFacade.create(talla);
         } catch (Exception e) {
         e.printStackTrace();
         }

     return "ubicacion3?faces-redirect=true";
     }

      public String Volver_Ubicacion3(){
return "index?faces-redirect=true";
     }
}
